
Imports System
Imports System.Collections
Imports System.ComponentModel
Imports System.Data
Imports System.Drawing
Imports System.Web
Imports System.Web.SessionState
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.Web.UI.HtmlControls
Imports _2bMatesSite.BO

Namespace _2bMatesSite
	''' <summary>
	''' Summary description for view_member_blog.
	''' </summary>
	Public Partial Class view_member_blog
		Inherits BaseWebPage
		Private memberID As Integer = -1
		Protected htPageConstants As New Hashtable()

		Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
			' Put user code to initialize the page here
			' this.pageTemplate.PageTitle = PageTitles.BLOG_PAGE;
			If LoggedUser <> Nothing Then
				Me.RegisterStartupScript("resizeImages", Constants.RESIZE_BLOG_IMAGE_SCRIPT)
				Me.pageTemplate.onLoadScript = "resizeImages()"

				Me.initPageTitles(Constants.VIEW_MEMBER_BLOG, "", Form1, Nothing, htPageConstants)
				Me.initAdvertisements(Form1, Nothing)

				If Request.Params("id") <> Nothing Then
					memberID = Convert.ToInt32(Request.Params("id"))
					Dim usr As User = Users.GetUserByID(memberID)

					If usr <> Nothing AndAlso usr.ID <> LoggedUser.ID Then
						ucMemberShortcut.UserID = usr.ID
					Else
						trUserShortCut.Visible = False
					End If

					If usr <> Nothing Then
						litMember.Text = usr.Name + "'s"
						If Not IsPostBack Then
							BindGrid()
						End If
							'report error
					Else
					End If
				End If
			Else
				Common.Utils.RedirectToLoginPage(Page)
			End If
		End Sub

		Protected Function CreateDataSource() As ICollection
			Dim usr As User = Users.GetUserByID(memberID)

			' removed by maz's request
			Dim bIsLoggedUserFriendOfBlogOwner As Boolean = True
			'usr.DirectFriends.Contains(LoggedUser.ID);
			Dim dt As New DataTable()
			Dim curBlogDate As DateTime

			' List user's inbox messages
			Dim blogList As ArrayList = Messages.GetUserBlogs(usr.ID)

			If blogList.Count = 0 Then
				lblNoBlog.Visible = True
			Else
				lblNoBlog.Visible = False
			End If
			Dim dr As DataRow
			dt.Columns.Add(New DataColumn("BlogID", GetType(Integer)))
			dt.Columns.Add(New DataColumn("Date", GetType(String)))
			dt.Columns.Add(New DataColumn("Time", GetType(String)))
			dt.Columns.Add(New DataColumn("Subject", GetType(String)))
			dt.Columns.Add(New DataColumn("Body", GetType(String)))
			dt.Columns.Add(New DataColumn("CommentsCount", GetType(String)))
			dt.Columns.Add(New DataColumn("CommentsCountVisible", GetType(Boolean)))
			dt.Columns.Add(New DataColumn("CommentsCountNullVisible", GetType(Boolean)))
			dt.Columns.Add(New DataColumn("ShowAddCommentLink", GetType(Boolean)))
			dt.Columns.Add(New DataColumn("ShowNotInFriendsListMsg", GetType(Boolean)))

			Dim blogComments As ArrayList
			' List user's inbox messages
			For Each blog As Blog In blogList
				dr = dt.NewRow()
				curBlogDate = blog.DateSent
				blogComments = Messages.GetUserBlogEntries(blog.ID)
				dr(0) = blog.ID
				dr(1) = curBlogDate.DayOfWeek + ", " + Constants.ARR_MONTHS(curBlogDate.Month - 1) + " " + curBlogDate.Day + ", " + curBlogDate.Year
				dr(2) = curBlogDate.ToShortTimeString()
				dr(3) = Server.HtmlEncode(blog.Subject)
				dr(4) = Me.initBlogMessage(blog.Body)
				'dr[5] = blogComments.Count + " " + "Comment";
				If blogComments.Count > 0 Then
					dr(5) = blogComments.Count + " " + "Comment"
					dr(6) = True
					dr(7) = False
				Else
					dr(5) = ""
					'dr[6] = "0 " + "Comments";
					dr(6) = False
					dr(7) = True
				End If
				If blogComments.Count <> 1 Then
					dr(5) += "s"
				End If

				dr(8) = bIsLoggedUserFriendOfBlogOwner
				dr(9) = Not bIsLoggedUserFriendOfBlogOwner

				dt.Rows.Add(dr)
			Next
			Dim dv As New DataView(dt)
			Return dv
		End Function

		Protected Sub BindGrid()
			dgMessages.DataSource = CreateDataSource()
			dgMessages.DataBind()
		End Sub


		#region Web Form Designer generated code
		Protected Overloads Overrides Sub OnInit(ByVal e As EventArgs)
			'
			' CODEGEN: This call is required by the ASP.NET Web Form Designer.
			'
			InitializeComponent()
			MyBase.OnInit(e)
		End Sub

		''' <summary>
		''' Required method for Designer support - do not modify
		''' the contents of this method with the code editor.
		''' </summary>
		Private Sub InitializeComponent()
			AddHandler Me.dgMessages.ItemCommand, AddressOf Me.dgMessages_ItemCommand

		End Sub
#End Region

		Private Sub dgMessages_ItemCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs)
			Dim usr As User = Users.GetUserByID(memberID)
			Dim btnPushed As LinkButton = DirectCast(e.CommandSource, LinkButton)
			Dim cmd As String = e.CommandName
			Select Case cmd
				Case "ViewComments"
					Response.Redirect(Constants.VIEW_MEMBER_BLOG_COMMENTS + "?id=" + e.CommandArgument + "&usr=" + memberID)
					Exit Select
				Case "AddComment"
					If LoggedUser.DirectFriends.Contains(memberID) Then
						Response.Redirect(Constants.POST_MEMBER_BLOG_COMMENT + "?id=" + e.CommandArgument + "&usr=" + memberID)
					Else
						lblNoBlog.Text = Me.GetPageConstText(htPageConstants, "CONST_MsgNoFriends_TEXT")
						lblNoBlog.Visible = True
						dgMessages.Visible = False
					End If
					Exit Select
			End Select
		End Sub

		Protected Sub dgMessages_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs)

		End Sub

		====================
		' This public property was added by conversion wizard to allow the access of a protected, autogenerated member variable Form1.
		====================
		Public ReadOnly Property Form1() As System.Web.UI.HtmlControls.HtmlForm
			Get
				Return Migrated_Form1
			End Get
		End Property
		'set { Migrated_Form1 = value; }
	End Class
End Namespace






